﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace BilingualSentIndexing
{
    class DictReader
    {
        Dictionary<int, string> termId2Str;
        Dictionary<string, int> termStr2Id;
        public void Open(string fileName)
        {
            termId2Str = new Dictionary<int, string>();
            termStr2Id = new Dictionary<string, int>();

            StreamReader sr = new StreamReader(fileName);
            while (sr.EndOfStream == false)
            {
                string strTerm, strId;
                strTerm = sr.ReadLine();
                strId = sr.ReadLine();

                termId2Str.Add(int.Parse(strId), strTerm);
                termStr2Id.Add(strTerm, int.Parse(strId));
            }
            sr.Close();
        }

        public string GetStrTermById(int termId)
        {
            string v;
            if (termId2Str.TryGetValue(termId, out v) == true)
            {
                return v;
            }
            return "";
        }

        public int GetTermId(string term)
        {
            int v;
            if (termStr2Id.TryGetValue(term, out v) == false)
            {
                return -1;
            }
            return v;
        }
    }
}
